#include "timer.h"

/* configure the TIMER peripheral */
void timer_config(void)
{
/* ----------------------------------------------------------------------------
	TIMER1 Configuration: 
	TIMER1CLK = SystemCoreClock/10800 = 10KHz, the period is 1s(10000/10000 = 1s).
	---------------------------------------------------------------------------- */
	timer_parameter_struct timer_initpara;
	rcu_periph_clock_enable(RCU_TIMER1);
	timer_deinit(TIMER1);
	/* initialize TIMER init parameter struct */
	timer_struct_para_init(&timer_initpara);
	/* TIMER1 configuration */
	timer_initpara.prescaler         = 10799;
	timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
	timer_initpara.counterdirection  = TIMER_COUNTER_UP;
	timer_initpara.period            = 9;
	timer_initpara.clockdivision     = TIMER_CKDIV_DIV1;
	timer_init(TIMER1, &timer_initpara);
	timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
	timer_interrupt_enable(TIMER1, TIMER_INT_UP);
	timer_enable(TIMER1);
}
